﻿using System.Collections.ObjectModel;

namespace Central.Linq {

	/// <summary>
	/// Класс результата агрегирующей функции поля сущности
	/// </summary>
	public class AggregateFieldResult {
		#region конструктор

		/// <summary>
		/// Конструктор
		/// </summary>
		public AggregateFieldResult() {
			this.AggregateFunctions = new Collection<AggregateFunctionResult>();
		}

		/// <summary>
		/// Конструктор
		/// </summary>
		public AggregateFieldResult(string field)
			: base() {
			this.Field = field;
		}

		/// <summary>
		/// Конструктор
		/// </summary>
		public AggregateFieldResult(string field, Collection<AggregateFunctionResult> aggregateFunctions) {
			this.Field = field;
			this.AggregateFunctions = aggregateFunctions;
		}

		#endregion конструктор

		/// <summary>
		/// Список результатов агрегирующих функций
		/// </summary>
		public Collection<AggregateFunctionResult> AggregateFunctions { get; private set; }

		/// <summary>
		/// Наименование поля сущности
		/// </summary>[DataMember]
		public string Field { get; set; }

		#region методы

		/// <summary>
		/// Метод добавления агрегирующей функции
		/// </summary>
		/// <param name="aggregateFunction">агрегирующая функция</param>
		public void Add(AggregateFunctionResult aggregateFunction) {
			if (aggregateFunction == null)
				return;

			if (this.AggregateFunctions == null)
				this.AggregateFunctions = new Collection<AggregateFunctionResult>();

			if (!this.AggregateFunctions.Contains(aggregateFunction))
				this.AggregateFunctions.Add(aggregateFunction);
		}

		/// <summary>
		/// Метод удаления агрегирующей функции из коллекции
		/// </summary>
		/// <param name="aggregateFunction">агрегирующая функция</param>
		public void Remove(AggregateFunctionResult aggregateFunction) {
			if (aggregateFunction == null)
				return;
			if (this.AggregateFunctions != null)
				this.AggregateFunctions.Remove(aggregateFunction);
		}

		/// <summary>
		/// Метод очищения коллекции агрегирующих функций
		/// </summary>
		public void Clear() {
			if (this.AggregateFunctions != null)
				this.AggregateFunctions.Clear();
		}

		#endregion методы
	}
}